﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SBACN.WebSite.Code;
using SBACN.WebSite.Models;
using System.Linq.Expressions;
using System.Text;

namespace SBACN.WebSite.ComDList
{
	public partial class ComDetail : MemberBasePage
	{
		protected string CTitle { get; set; }
		protected string Con1 { get; set; }
		protected string Con2 { get; set; }
		protected string Con3 { get; set; }
		protected string Img { get; set; }

		protected void Page_Load(object sender, EventArgs e)
		{
			if (string.IsNullOrWhiteSpace(Request.QueryString["id"]))
			{
				//this.Con2 = "<a href='../MemberMsg/MemberShow.aspx?st=" + this.SystemCode + "' target='_blank'>>>查看会员单位</a>";
				this.Con3 = "<a href='ComList.aspx?st=" + this.SystemCode + "' target='_blank'><img src='../images/title_icon.gif' width='14' height='14' />历届理事会</a>";
				this.Img = "tenth_img.jpg";
				//DataC();
			}
			else
			{
				//this.Con2 = "<a href='../MemberMsg/MemberShow.aspx?st=" + this.SystemCode + "&id=" + Request.QueryString["id"] + "' target='_blank'>>>查看会员单位</a>";
				this.Img = "Council_img.jpg";
			}

			BindData(Request.QueryString["id"]);

		}

		protected void BindData(string id)
		{
			Expression<Func<TB_CouncilInfo, bool>> f;
			if (string.IsNullOrWhiteSpace(id))
			{
				f = (p => p.Status);
			}
			else
			{
				int ID = Convert.ToInt32(id);
				f = (p => p.Index == ID);
			}

			var resultQ = DAL.DALHelper.Instance.GetFirstOrDefaultObject<TB_CouncilInfo>(f);
			if (resultQ != null)
			{
				string StrTitle = resultQ.Name.ToString() + "&nbsp;（";

				if (Convert.ToDateTime(resultQ.StartTime).ToString("yyyy-MM-dd") == "0001-01-01")
					StrTitle = StrTitle + " ";
				else
					StrTitle = StrTitle + resultQ.StartTime.ToString("yyyy.MM");


				if (Convert.ToDateTime(resultQ.EndTime).ToString("yyyy-MM-dd") == "0001-01-01")
					StrTitle = StrTitle + " - 至今）";
				else
					StrTitle = StrTitle +" - "+ Convert.ToDateTime( resultQ.EndTime).ToString("yyyy.MM") + "）";

				this.CTitle = StrTitle;
				this.Con1 = resultQ.Memo.ToString();
			}
		}

		protected void DataC()
		{
			// 部分成员单位介绍(000100050001 000100050002 000100050004 000100050005)
			string[] Member = { "000100050001", "000100050002", "000100050004", "000100050005" };
			string CHtml = "<p dir='ltr' align='left'><strong>—会员单位—</strong><br /><br /></p>";
			foreach (string l in Member)
			{
				CHtml = CHtml + MemberMsg(l);
			}

			this.Con2 = CHtml;
			this.Con3 = "<a href='ComList.aspx?st=" + this.SystemCode + "'><img src='../images/title_icon.gif' width='14' height='14' />历届理事会</a>";
		}

		protected string MemberMsg(string Code)
		{

			var resultC = DAL.DALHelper.Instance.GetObject<TB_SystemMap>("Code", Code);


			Expression<Func<TB_Member, bool>> f = (p => (p.Status));
			Expression<Func<TB_Member, string>> order = (c => (c.Name));
			var resultM = DAL.DALHelper.Instance.GetList<TB_Member, string>(f, order, true);

			StringBuilder MHtml = new StringBuilder();

			if (resultM.Count > 0 && resultC != null)
			{

				string MTi = "<div ><strong>" + resultC.Name + "</strong></div><ul>";
				MHtml.Append(MTi);
				foreach (var l in resultM)
				{
					string Msg = "<li>" + l.Name + "</li>";
					MHtml.Append(Msg);
				}
				MHtml.Append("</ul>");
			}

			return MHtml.ToString();
		}

	}
}